package rsj.api.test.offline;

import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import com.rlyy.aibase.utils.base.TableNode;
import common.util.BoxUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.user.BaseLink;
import rsj.service.IExecuteInterface;
import common.util.QueryRunnerFactory;

import java.sql.SQLException;

/**
 * 数据录入-查询测试数据下拉
 *
 * @author yuanqinglong
 * @since 2021/3/15 16:21
 */
@RestController
public class ProdNameSelectController extends BaseLink {

    Logger logger = LoggerFactory.getLogger(ProdNameSelectController.class);
    /**
     * 数据录入-查询测试数据下拉
     *
     * @param box 参数
     * @return 客户简称下拉
     * @throws SQLException 异常
     */
    @Override
    @RequestMapping(value = "rsj_add_data_select_prod")
    public Box executeLink(Box box) throws SQLException {
        MapNode mapNode = new MapNode().putTableNode("List", this.queryOrgNames());
        return BoxUtil.successBox(box).putMapNode("data", mapNode);
    }


    /**
     * 查询测试数据下拉
     *
     * @return 列表
     */
    private TableNode queryOrgNames() {
        String sql = " SELECT prod_id , prod_name FROM sys.sys_prod ";
        return (TableNode) IExecuteInterface.doExecuteQuery(connection ->
                QueryRunnerFactory.getQueryRunner().queryLinkTableNode(connection, sql),
                e -> logger.error("查询测试数据下拉失败,{}", e));
    }
}
